package server.controller.affiche;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import server.db.primary.mapper.map.AfficheAppMapper;
import server.db.primary.mapper.map.AfficheMapper;
import server.db.primary.model.map.Affiche;
import server.db.primary.model.map.AfficheApp;
import server.tool.Res;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController

public class AfficheController {
    @Autowired
    AfficheMapper afficheMapper;
    @Autowired
    AfficheAppMapper afficheAppMapper;

    /**
     *  插入公告。。。。。。。
     * @param affiche
     * @return
     */
    @RequestMapping("/Affiche/save")
    public Res afficheByInsert(Affiche affiche) {
        Map<String,Object> map = new HashMap<>();
        int i = afficheMapper.insertSelective(affiche);
        map.put("number",affiche.getNumberId());
        map.put("data",affiche.getData());
        map.put("data2",affiche.getData2());
        return Res.success(map);
    }

    /**
     * 申请人代办（0提交，1暂存）
     * @param afficheId
     * @param mark1
     * @return
     */
    @RequestMapping("/Affiche/afficheId")
    public Res sealByuserId(Integer afficheId,Integer mark1,String timeStart ,String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectByuserId(afficheId,mark1,timeStart,timeEnd);
        return Res.success(affiches);
    }
    /**
     * 通过id修改信息
     * @param affiche
     * @return 123132
     */
    @RequestMapping("/Affiche/updatebyid")
    public Res updatebyid(Affiche affiche) {
        Map<String,Object> map = new HashMap<>();
        int i = afficheMapper.updateByPrimaryKeySelective(affiche);
        map.put("id",affiche.getId());
        map.put("data",affiche.getData());
        map.put("data2",affiche.getData2());
        return Res.success(map);
    }

    /**
     * 通过id删除信息
     * @param id
     * @return 1112312
     */
    @RequestMapping("/Affiche/delete")
    public Res delete(long id) {
        int delete = afficheMapper.deleteByPrimaryKey(id);
        return Res.success(delete);
    }


    /**
     * 查询表里的所有数据
     * @return
     */
    @RequestMapping("/Affiche/findAll")
    public Res findAll() {
        List<Affiche> affiches = afficheMapper.selectByAll();
        return Res.success(affiches);
    }

    /**
     * 查询最后一条流水号
     * @return
     */
    @RequestMapping("/Affiche/numberid")
    public Res affcheBynumberId() {
        List<Affiche> affiches = afficheMapper.selectBynumberId();
        return Res.success(affiches);
    }

    /**
     * 通过id查询某一条数据
     * @param id
     * @return
     */
    @RequestMapping("/Affiche/id")
    public Res affichebyid(long id) {
        Affiche affiche = afficheMapper.selectByPrimaryKey(id);
        return Res.success(affiche);
    }

    /**
     * 部门领导已办
     * @param userId
     * @param wellUserId
     * @return
     */
    @RequestMapping("/Affiche/welluserId")
    public Res sealBywelluserId(Integer userId,Integer wellUserId,String timeStart ,String timeEnd,String timeStart1 ,String timeEnd1) {
        List<Affiche> affiches = afficheMapper.selectBywelluserId(userId,wellUserId,timeStart,timeEnd,timeStart1,timeEnd1);
        return Res.success(affiches);
    }

    /**
     * 部门领导办结
     * @param userId
     * @param wellUserId
     * @return
     */
    @RequestMapping("/Affiche/welluserIdmark")
    public Res sealBywelluserIdmark(Integer userId,Integer wellUserId,String timeStart ,String timeEnd,String timeStart1 ,String timeEnd1) {
        List<Affiche> affiches = afficheMapper.selectBywelluserIdmark(userId,wellUserId,timeStart,timeEnd,timeStart1,timeEnd1);
        return Res.success(affiches);
    }

    /**
     * 部门领导待办
     * @param
     * @return
     */
    @RequestMapping("/Affiche/notwelluserId")
    public Res sealnotBywelluserId(Integer userId,Integer wellUserId,String timeStart ,String timeEnd,String timeStart1 ,String timeEnd1) {
        List<Affiche> affiches = afficheMapper.selectnotBywelluserId(userId,wellUserId,timeStart,timeEnd,timeStart1,timeEnd1);
        return Res.success(affiches);
    }

    /**
     * 公司领导待办
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/notstationuserId")
    public Res sealnotBystationuserId(Integer stationUserId,String timeStart ,String timeEnd) {
        List<Affiche> affiche = afficheMapper.selectnotBystationuserId(stationUserId,timeStart ,timeEnd);
        return  Res.success(affiche);
    }

    /**
     * 公司领导 已办
     * @return
     */
    @RequestMapping("/Affiche/BystationuserId")
    public  Res sealBystationuserId(Integer stationUserId,String timeStart ,String timeEnd) {
        List<Affiche> affiche = afficheMapper.selectBystationuserId(stationUserId,timeStart,timeEnd);
        return Res.success(affiche);
    }

    /**
     * 公司领导 办结
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/stationuserIdmark")
    public Res stationuserIdmark(Integer stationUserId,String timeStart ,String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectBystationuserIdmark(stationUserId, timeStart, timeEnd);

        return Res.success(affiches);
    }


    /**
     * 归档人查询(待办，办结)
     * @param mark
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/notmark")
    public Res sealBynotmark(Integer mark,String timeStart, String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectnotBymark(mark,timeStart, timeEnd);
        return Res.success(affiches);
    }

    /**
     * 归档人查询(流程监控)
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/mark")
    public Res sealBymark(String timeStart, String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectBymark(timeStart, timeEnd);
        return Res.success(affiches);
    }

    /**
     * 归档人查询（暂存,公司领导办结）
     * @param userId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/sealectgonggao")
    public Res sealectgonggao(Integer userId,String timeStart ,String timeEnd,String timeStart1 ,String timeEnd1) {
        List<Affiche> selectguidang = afficheMapper.selectguidang(userId, timeStart, timeEnd, timeStart1, timeEnd1);
        return Res.success(selectguidang);
    }

    /**
     * 归档人提交数据
     * @param userId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/selectdone")
    public Res selectdone(Integer userId,String timeStart ,String timeEnd) {
        List<Affiche> selectdone = afficheMapper.selectdone(userId, timeStart, timeEnd);
        return Res.success(selectdone);
    }


    /**
     * 申请人归档信息
     * @param userId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/selectUserId")
    public Res selectUserId(Integer userId,String timeStart ,String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectUserId(userId, timeStart, timeEnd);
        return Res.success(affiches);
    }

    /**
     * 部门领导归档信息
     * @param wellUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/selectwellUserId")
    public Res selectWell_User_Id(Integer wellUserId,String timeStart ,String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectwellUserId(wellUserId, timeStart, timeEnd);
        return Res.success(affiches);
    }

    /**
     * 公司领导归档信息
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/Affiche/selectstationUserId")
    public Res selectstationUserId(Integer stationUserId,String timeStart ,String timeEnd) {
        List<Affiche> affiches = afficheMapper.selectstationUserId(stationUserId, timeStart, timeEnd);
        return Res.success(affiches);
    }

    /**
     * 附件查询
     * @param id
     * @return
     */
    @RequestMapping("/Affiche/BynumberId")
    public Res selectSealApp(long id) {

        Affiche affiche = afficheMapper.selectByPrimaryKey(id);

        Long numberId = affiche.getNumberId();

        List<AfficheApp> afficheApps = afficheAppMapper.selectByNumberId(numberId);

        Map<String, Object> map = new HashMap<>();

        map.put("Affiche", affiche);
//        map.put("AfficheApp", afficheApps);
        return Res.success(map);
    }
}
